/*
 * Tezad - Classic puzzle game
 * Copyright 2009 Shayne Riley and Paul Maseberg
 *
 * Tezad is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Tezad is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Tezad.  If not, see <http://www.gnu.org/licenses/>
 * or write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * To contact the authors on questions or issues regarding the license,
 * you may send an email to <pezads at gmail dot com>
 */

#ifndef GAMEMINOENGINE_H_
#define GAMEMINOENGINE_H_

#include "GameWell.h"
#include "GameMinoState.h"
#include "GameMinoStruct.h"

class GameMinoEngine
{
public:
    /**
     * Determine if it is legal for the tetromino to be placed in its current
     * location.
     *
     * It is a legal tetromino placement if:
     * - No bricks of the tetromino overlap other bricks in the well.
     * - No bricks of the tetromino are outside of the well.
     *
     * @param well The well that has previously laid bricks.
     * @param minoState The position and location of the active tetromino.
     * @param mino  The shape of the mino.
     * @return True if it is legal for the mino to be placed where minoState
     * indicates.
     */
    bool isMinoPlacementLegal(const GameWell& well,
            const GameMinoState& minoState, const GameMinoStruct& mino);
    /**
    * Determines what the state of the Mino would be if it were dropped to its
    * lowest vertical position. This is useful for getting the preview Mino of
    * the setting position.
    *
    * @return The lowest legal position of the Mino, if its rotation and
    * horizontal position were kept the same. If the Mino is currently in an
    * illegal state, or if the position below would be illegal, then it returns
    * the current position of the Mino.
    */
    GameMinoState settingMinoState(const GameWell& well,
            const GameMinoState& minoState, const GameMinoStruct& mino);

    /**
     * Sets the mino inside the well at the given position. Any bricks that
     * previously existed where the new bricks are to be placed will be
     * overwritten. Any bricks of the mino that lay outside of the well will
     * not be written.
     * @param well  Write the bricks to this well.
     * @param minoState The placement and rotation of the mino.
     * @param mino  Contains the structure of the mino. This will get
     * written to the well.
     */
    void setMino(GameWell& well, const GameMinoState& minoState,
            const GameMinoStruct& mino);
};

#endif /* GAMEMINOENGINE_H_ */
